/******************************************************************************/
/*  Flash memory map for SmartBUG                                             */
/*                                                                            */
/*  Revision:     1.0                                                         */
/*  Date:         2011/01/09 21:45:33                                         */
/******************************************************************************/

#ifndef __FMEM_MAP_H
#define __FMEM_MAP_H


#define FMEMORY_VOLUME        (0x00400000)

/******************************************************************************/
/*                        SmartBUG settings                                   */
/******************************************************************************/
#define GSETT_START_ADDR      (0)
#define GSETT_MEM_SIZE        (65536 * 2)                     // 128 kByte

#define GSSWOP_START_ADDR     (GSETT_START_ADDR + GSETT_MEM_SIZE)
#define GSSWOP_MEM_SIZE       (4096)                          // 4 kB


/************************** Generic settings **********************************/
#define MEM_FLG_CFG           (GSETT_MEM_SIZE - 2)            // Flg def cfg 2 bytes
#define MEM_DEV_ID            (0)                             // Device id 4 bytes
#define MEM_MB_ADDR           (MEM_DEV_ID + 4)                // Device modbus addr 1 + 1 byte
#define MEM_PACK_SEND_TIME    (MEM_MB_ADDR + 2)               // Timer value for sending pack
#define MEM_RFILE_POLL_TIME   (MEM_PACK_SEND_TIME + 4)        // Timer value for poll rfile  


/**************************** Din settings ************************************/
#define MEM_DIN1_SETT         (MEM_DEV_ID + 512)              // Din1 sett
#define MEM_DIN2_SETT         (MEM_DIN1_SETT + 6)             // Din2 sett
#define MEM_DIN3_SETT         (MEM_DIN2_SETT + 6)             // Din3 sett
#define MEM_DIN4_SETT         (MEM_DIN3_SETT + 6)             // Din4 sett
#define MEM_DIN5_SETT         (MEM_DIN4_SETT + 6)             // Din5 sett
#define MEM_DIN6_SETT         (MEM_DIN5_SETT + 6)             // Din6 sett

#define MEM_ACT_DIN1_ON       (MEM_DIN6_SETT + 6)             // Din1_on act
#define MEM_ACT_DIN1_OFF      (MEM_ACT_DIN1_ON + 64)          // Din1_off act
#define MEM_ACT_DIN2_ON       (MEM_ACT_DIN1_OFF + 64)         // Din2_on act
#define MEM_ACT_DIN2_OFF      (MEM_ACT_DIN2_ON + 64)          // Din1_off act
#define MEM_ACT_DIN3_ON       (MEM_ACT_DIN2_OFF + 64)         // Din3_on act
#define MEM_ACT_DIN3_OFF      (MEM_ACT_DIN3_ON + 64)          // Din1_off act
#define MEM_ACT_DIN4_ON       (MEM_ACT_DIN3_OFF + 64)         // Din4_on act
#define MEM_ACT_DIN4_OFF      (MEM_ACT_DIN4_ON + 64)          // Din1_off act
#define MEM_ACT_DIN5_ON       (MEM_ACT_DIN4_OFF + 64)         // Din5_on act
#define MEM_ACT_DIN5_OFF      (MEM_ACT_DIN5_ON + 64)          // Din1_off act
#define MEM_ACT_DIN6_ON       (MEM_ACT_DIN5_OFF + 64)         // Din6_on act
#define MEM_ACT_DIN6_OFF      (MEM_ACT_DIN6_ON + 64)          // Din1_off act


/***************************** Ain settings ***********************************/
#define MEM_AIN1_SETT         (MEM_ACT_DIN6_OFF + 64)         // Ain1 sett
#define MEM_AIN2_SETT         (MEM_AIN1_SETT + 24)            // Ain2 sett
#define MEM_AIN3_SETT         (MEM_AIN2_SETT + 24)            // Ain3 sett

#define MEM_ACT_AIN1_MAX1     (MEM_AIN3_SETT + 24)            // Ain1_max1 actions
#define MEM_ACT_AIN1_MIN1     (MEM_ACT_AIN1_MAX1 + 64)        // Ain1_min1 actions
#define MEM_ACT_AIN1_MAX2     (MEM_ACT_AIN1_MIN1 + 64)        // Ain1_max2 actions
#define MEM_ACT_AIN1_MIN2     (MEM_ACT_AIN1_MAX2 + 64)        // Ain1_min2 actions
#define MEM_ACT_AIN1_MAX3     (MEM_ACT_AIN1_MIN2 + 64)        // Ain1_max3 actions
#define MEM_ACT_AIN1_MIN3     (MEM_ACT_AIN1_MAX3 + 64)        // Ain1_min3 actions
#define MEM_ACT_AIN1_MAX4     (MEM_ACT_AIN1_MIN3 + 64)        // Ain1_max4 actions
#define MEM_ACT_AIN1_MIN4     (MEM_ACT_AIN1_MAX4 + 64)        // Ain1_min4 actions

#define MEM_ACT_AIN2_MAX1     (MEM_ACT_AIN1_MIN4 + 64)        // Ain2_max1 actions
#define MEM_ACT_AIN2_MIN1     (MEM_ACT_AIN2_MAX1 + 64)        // Ain2_min1 actions
#define MEM_ACT_AIN2_MAX2     (MEM_ACT_AIN2_MIN1 + 64)        // Ain2_max2 actions
#define MEM_ACT_AIN2_MIN2     (MEM_ACT_AIN2_MAX2 + 64)        // Ain2_min2 actions
#define MEM_ACT_AIN2_MAX3     (MEM_ACT_AIN2_MIN2 + 64)        // Ain2_max3 actions
#define MEM_ACT_AIN2_MIN3     (MEM_ACT_AIN2_MAX3 + 64)        // Ain2_min3 actions
#define MEM_ACT_AIN2_MAX4     (MEM_ACT_AIN2_MIN3 + 64)        // Ain2_max4 actions
#define MEM_ACT_AIN2_MIN4     (MEM_ACT_AIN2_MAX4 + 64)        // Ain2_min4 actions

#define MEM_ACT_AIN3_MAX1     (MEM_ACT_AIN2_MIN4 + 64)        // Ain3_max1 actions
#define MEM_ACT_AIN3_MIN1     (MEM_ACT_AIN3_MAX1 + 64)        // Ain3_min1 actions
#define MEM_ACT_AIN3_MAX2     (MEM_ACT_AIN3_MIN1 + 64)        // Ain3_max2 actions
#define MEM_ACT_AIN3_MIN2     (MEM_ACT_AIN3_MAX2 + 64)        // Ain3_min2 actions
#define MEM_ACT_AIN3_MAX3     (MEM_ACT_AIN3_MIN2 + 64)        // Ain3_max3 actions
#define MEM_ACT_AIN3_MIN3     (MEM_ACT_AIN3_MAX3 + 64)        // Ain3_min3 actions
#define MEM_ACT_AIN3_MAX4     (MEM_ACT_AIN3_MIN3 + 64)        // Ain3_max4 actions
#define MEM_ACT_AIN3_MIN4     (MEM_ACT_AIN3_MAX4 + 64)        // Ain3_min4 actions


/**************************** Temp sensor settings ****************************/
#define MEM_TEMP1_SETT        (MEM_ACT_AIN3_MIN4  + 64)       // Temp sens1 sett
#define MEM_TEMP2_SETT        (MEM_TEMP1_SETT + 20)           // Temp sens2 sett
#define MEM_TEMP3_SETT        (MEM_TEMP2_SETT + 20)           // Temp sens3 sett

#define MEM_UID_TEMP1         (MEM_TEMP3_SETT + 20)           // Temp sens1 uid
#define MEM_UID_TEMP2         (MEM_UID_TEMP1 + 8)             // Temp sens2 uid
#define MEM_UID_TEMP3         (MEM_UID_TEMP2 + 8)             // Temp sens3 uid

#define MEM_ACT_TEMP1_MAX1    (MEM_UID_TEMP3 + 8)             // Temp1_max1 act
#define MEM_ACT_TEMP1_MIN1    (MEM_ACT_TEMP1_MAX1 + 64)       // Temp1_min1 act
#define MEM_ACT_TEMP1_MAX2    (MEM_ACT_TEMP1_MIN1 + 64)       // Temp1_max2 act
#define MEM_ACT_TEMP1_MIN2    (MEM_ACT_TEMP1_MAX2 + 64)       // Temp1_min2 act
#define MEM_ACT_TEMP1_MAX3    (MEM_ACT_TEMP1_MIN2 + 64)       // Temp1_max3 act
#define MEM_ACT_TEMP1_MIN3    (MEM_ACT_TEMP1_MAX3 + 64)       // Temp1_min3 act
#define MEM_ACT_TEMP1_MAX4    (MEM_ACT_TEMP1_MIN3 + 64)       // Temp1_max4 act
#define MEM_ACT_TEMP1_MIN4    (MEM_ACT_TEMP1_MAX4 + 64)       // Temp1_min4 act

#define MEM_ACT_TEMP2_MAX1    (MEM_ACT_TEMP1_MIN4 + 64)       // Temp2_max1 act
#define MEM_ACT_TEMP2_MIN1    (MEM_ACT_TEMP2_MAX1 + 64)       // Temp2_min1 act
#define MEM_ACT_TEMP2_MAX2    (MEM_ACT_TEMP2_MIN1 + 64)       // Temp2_max2 act
#define MEM_ACT_TEMP2_MIN2    (MEM_ACT_TEMP2_MAX2 + 64)       // Temp2_min2 act
#define MEM_ACT_TEMP2_MAX3    (MEM_ACT_TEMP2_MIN2 + 64)       // Temp2_max3 act
#define MEM_ACT_TEMP2_MIN3    (MEM_ACT_TEMP2_MAX3 + 64)       // Temp2_min3 act
#define MEM_ACT_TEMP2_MAX4    (MEM_ACT_TEMP2_MIN3 + 64)       // Temp2_max4 act
#define MEM_ACT_TEMP2_MIN4    (MEM_ACT_TEMP2_MAX4 + 64)       // Temp2_min4 act

#define MEM_ACT_TEMP3_MAX1    (MEM_ACT_TEMP2_MIN4 + 64)       // Temp3_max1 act
#define MEM_ACT_TEMP3_MIN1    (MEM_ACT_TEMP3_MAX1 + 64)       // Temp3_min1 act
#define MEM_ACT_TEMP3_MAX2    (MEM_ACT_TEMP3_MIN1 + 64)       // Temp3_max2 act
#define MEM_ACT_TEMP3_MIN2    (MEM_ACT_TEMP3_MAX2 + 64)       // Temp3_min2 act
#define MEM_ACT_TEMP3_MAX3    (MEM_ACT_TEMP3_MIN2 + 64)       // Temp3_max3 act
#define MEM_ACT_TEMP3_MIN3    (MEM_ACT_TEMP3_MAX3 + 64)       // Temp3_min3 act
#define MEM_ACT_TEMP3_MAX4    (MEM_ACT_TEMP3_MIN3 + 64)       // Temp3_max4 act
#define MEM_ACT_TEMP3_MIN4    (MEM_ACT_TEMP3_MAX4 + 64)       // Temp3_min4 act


/***************************** Relay settings *********************************/
#define MEM_RELAY1_SETT       (MEM_ACT_TEMP3_MIN4 + 64)       // Relay1 sett
#define MEM_RELAY2_SETT       (MEM_RELAY1_SETT + 4)           // Relay2 sett


/***************************** Ethernet settings ******************************/
#define MEM_MAC               (MEM_RELAY1_SETT + 256)         // Mac addr 6 bytes
#define MEM_DEV_IP            (MEM_MAC + 6)                   // Device ip-addr 4 bytes
#define MEM_GATEWAY           (MEM_DEV_IP + 4)                // Device gateway 4 bytes
#define MEM_NETMASK           (MEM_GATEWAY + 4)               // Device netmask 4 bytes

#define MEM_ENET_SRV_ENABLE   (MEM_NETMASK + 4)               // Flg en/dis srvs 2 bytes

#define MEM_ENET_SRV1_TYPE    (MEM_ENET_SRV_ENABLE + 2)       // Rem srv1 type 2 bytes
#define MEM_ENET_SRV1_IP      (MEM_ENET_SRV1_TYPE + 2)        // Rem srv1 ip 4 bytes
#define MEM_ENET_SRV1_PORT    (MEM_ENET_SRV1_IP + 4)          // Rem srv1 port 2 bytes

#define MEM_ENET_SRV2_TYPE    (MEM_ENET_SRV1_PORT + 2)        // Rem srv2 type 2 bytes
#define MEM_ENET_SRV2_IP      (MEM_ENET_SRV2_TYPE + 2)        // Rem srv2 ip 4 bytes
#define MEM_ENET_SRV2_PORT    (MEM_ENET_SRV2_IP + 4)          // Rem srv2 port 2 bytes

#define MEM_ENET_SRV3_TYPE    (MEM_ENET_SRV2_PORT + 2)        // Rem srv3 type 2 bytes
#define MEM_ENET_SRV3_IP      (MEM_ENET_SRV3_TYPE + 2)        // Rem srv3 ip 4 bytes
#define MEM_ENET_SRV3_PORT    (MEM_ENET_SRV3_IP + 4)          // Rem srv3 port 2 bytes


/******************************* Modem settings *******************************/
#define MEM_APN               (MEM_MAC + 256)                 // Apn string 34 bytes
#define MEM_USERNAME          (MEM_APN + 34)                  // Username string 34 bytes
#define MEM_PASSWORD          (MEM_USERNAME + 34)             // Password string 34 bytes
#define MEM_PIN               (MEM_PASSWORD + 34)             // Pin string 6 bytes

#define MEM_MOD_SRV_ENABLE    (MEM_PIN + 6)                   // Flg en/dis srvs 2 bytes

#define MEM_MOD_SRV1_TYPE     (MEM_MOD_SRV_ENABLE + 2)        // Rem srv1 type 2 bytes
#define MEM_MOD_SRV1_IP       (MEM_MOD_SRV1_TYPE + 2)         // Rem srv1 ip 4 bytes
#define MEM_MOD_SRV1_PORT     (MEM_MOD_SRV1_IP + 4)           // Rem srv1 port 2 bytes

#define MEM_MOD_SRV2_TYPE     (MEM_MOD_SRV1_PORT + 2)         // Rem srv2 type 2 bytes
#define MEM_MOD_SRV2_IP       (MEM_MOD_SRV2_TYPE + 2)         // Rem srv2 ip 4 bytes
#define MEM_MOD_SRV2_PORT     (MEM_MOD_SRV2_IP + 4)           // Rem srv2 port 2 bytes

#define MEM_MOD_SRV3_TYPE     (MEM_MOD_SRV2_PORT + 2)         // Rem srv3 type 2 bytes
#define MEM_MOD_SRV3_IP       (MEM_MOD_SRV3_TYPE + 2)         // Rem srv3 ip 4 bytes
#define MEM_MOD_SRV3_PORT     (MEM_MOD_SRV3_IP + 4)           // Rem srv3 port 2 bytes


/******************************* Sms user settings ****************************/
#define MEM_SMS_USR_NUM       (16)
#define MEM_SMS_USR_SIZE      (14)
#define MEM_SMS_USR1          (MEM_MOD_SRV3_PORT + 2)         // Sms-usr1
#define MEM_SMS_USR2          (MEM_SMS_USR1 + 14)             // Sms-usr2
#define MEM_SMS_USR3          (MEM_SMS_USR2 + 14)             // Sms-usr3
#define MEM_SMS_USR4          (MEM_SMS_USR3 + 14)             // Sms-usr4
#define MEM_SMS_USR5          (MEM_SMS_USR4 + 14)             // Sms-usr5
#define MEM_SMS_USR6          (MEM_SMS_USR5 + 14)             // Sms-usr6
#define MEM_SMS_USR7          (MEM_SMS_USR6 + 14)             // Sms-usr7
#define MEM_SMS_USR8          (MEM_SMS_USR7 + 14)             // Sms-usr8
#define MEM_SMS_USR9          (MEM_SMS_USR8 + 14)             // Sms-usr9
#define MEM_SMS_USR10         (MEM_SMS_USR9 + 14)             // Sms-usr10
#define MEM_SMS_USR11         (MEM_SMS_USR10 + 14)            // Sms-usr11
#define MEM_SMS_USR12         (MEM_SMS_USR11 + 14)            // Sms-usr12
#define MEM_SMS_USR13         (MEM_SMS_USR12 + 14)            // Sms-usr13
#define MEM_SMS_USR14         (MEM_SMS_USR13 + 14)            // Sms-usr14
#define MEM_SMS_USR15         (MEM_SMS_USR14 + 14)            // Sms-usr15
#define MEM_SMS_USR16         (MEM_SMS_USR15 + 14)            // Sms-usr16


/***************************** Sms server settings ****************************/
#define MEM_SMS_SRV1          (MEM_SMS_USR16 + 14)            // Sms-srv1
#define MEM_SMS_SRV2          (MEM_SMS_SRV1 + 14)             // Sms-srv2
#define MEM_SMS_SRV3          (MEM_SMS_SRV2 + 14)             // Sms-srv3
#define MEM_SMS_SRV4          (MEM_SMS_SRV3 + 14)             // Sms-srv4
#define MEM_SMS_SRV5          (MEM_SMS_SRV4 + 14)             // Sms-srv5
#define MEM_SMS_SRV6          (MEM_SMS_SRV5 + 14)             // Sms-srv6
#define MEM_SMS_SRV7          (MEM_SMS_SRV6 + 14)             // Sms-srv7
#define MEM_SMS_SRV8          (MEM_SMS_SRV7 + 14)             // Sms-srv8
#define MEM_SMS_SRV9          (MEM_SMS_SRV8 + 14)             // Sms-srv9
#define MEM_SMS_SRV10         (MEM_SMS_SRV9 + 14)             // Sms-srv10
#define MEM_SMS_SRV11         (MEM_SMS_SRV10 + 14)            // Sms-srv11
#define MEM_SMS_SRV12         (MEM_SMS_SRV11 + 14)            // Sms-srv12
#define MEM_SMS_SRV13         (MEM_SMS_SRV12 + 14)            // Sms-srv13
#define MEM_SMS_SRV14         (MEM_SMS_SRV13 + 14)            // Sms-srv14
#define MEM_SMS_SRV15         (MEM_SMS_SRV14 + 14)            // Sms-srv15
#define MEM_SMS_SRV16         (MEM_SMS_SRV15 + 14)            // Sms-srv16
#define MEM_SMS_SRV17         (MEM_SMS_SRV16 + 14)            // Sms-srv17
#define MEM_SMS_SRV18         (MEM_SMS_SRV17 + 14)            // Sms-srv18
#define MEM_SMS_SRV19         (MEM_SMS_SRV18 + 14)            // Sms-srv19
#define MEM_SMS_SRV20         (MEM_SMS_SRV19 + 14)            // Sms-srv20
#define MEM_SMS_SRV21         (MEM_SMS_SRV20 + 14)            // Sms-srv21
#define MEM_SMS_SRV22         (MEM_SMS_SRV21 + 14)            // Sms-srv22
#define MEM_SMS_SRV23         (MEM_SMS_SRV22 + 14)            // Sms-srv23
#define MEM_SMS_SRV24         (MEM_SMS_SRV23 + 14)            // Sms-srv24
#define MEM_SMS_SRV25         (MEM_SMS_SRV24 + 14)            // Sms-srv25
#define MEM_SMS_SRV26         (MEM_SMS_SRV25 + 14)            // Sms-srv26
#define MEM_SMS_SRV27         (MEM_SMS_SRV26 + 14)            // Sms-srv27
#define MEM_SMS_SRV28         (MEM_SMS_SRV27 + 14)            // Sms-srv28
#define MEM_SMS_SRV29         (MEM_SMS_SRV28 + 14)            // Sms-srv29
#define MEM_SMS_SRV30         (MEM_SMS_SRV29 + 14)            // Sms-srv30
#define MEM_SMS_SRV31         (MEM_SMS_SRV30 + 14)            // Sms-srv31
#define MEM_SMS_SRV32         (MEM_SMS_SRV31 + 14)            // Sms-srv32


/********************************* Sms text ***********************************/
#define MEM_SMS_TEXT          (MEM_SMS_SRV32 + 14)            // Sms text block
#define MEM_SMS_SIZE          (40)                            // Sms size
#define MEM_SMS_TEXT_END      (MEM_SMS_TEXT + 100 * MEM_SMS_SIZE)


/***************************** Devices settings *******************************/
#define MEM_DQUERY_DATA_SIZE  (88)
#define MEM_DQUERY_NUM        (128)
#define MEM_DQUERY_BL_START   (MEM_SMS_TEXT_END)
#define MEM_DQUERY_BL_END     (MEM_DQUERY_BL_START + MEM_DQUERY_DATA_SIZE * MEM_DQUERY_NUM)


/**************************** Processor settings ******************************/
#define MEM_DPROC_DATA_SIZE   (22)
#define MEM_DPROC_NUM         (512)
#define MEM_DPROC_BL_START    (MEM_DQUERY_BL_END)
#define MEM_DPROC_BL_END      (MEM_DPROC_BL_START + MEM_DPROC_DATA_SIZE * MEM_DPROC_NUM)


/**************************** Setpoints settings ******************************/
#define MEM_SP_DATA_SIZE      (28)
#define MEM_SETPOINT_NUM      (128)
#define MEM_SP_ACT_SIZE       (256)
#define MEM_SP_BL_START       (MEM_DPROC_BL_END)
#define MEM_SP_BL_END         (MEM_SP_BL_START + MEM_SP_DATA_SIZE * MEM_SETPOINT_NUM)
#define MEM_SP_ACT_BL_START   (MEM_SP_BL_END)
#define MEM_SP_ACT_BL_END     (MEM_SP_ACT_BL_START + MEM_SP_ACT_SIZE * MEM_SETPOINT_NUM)


/******************************* Packet settings ******************************/
#define MEM_PACK_DATA_SIZE    (28)
#define MEM_PACK_NUM          (256)
#define MEM_PACK_BL_START     (MEM_SP_ACT_BL_END)
#define MEM_PACK_BL_END       (MEM_PACK_BL_START + MEM_PACK_DATA_SIZE * MEM_PACK_NUM)


/******************************* Log settings *********************************/
#define MEM_LOG_HEADER_SIZE   (16)
#define MEM_LOG_PARAM_SIZE    (9 * 32)
#define MEM_LOG_NUM           (11)
#define MEM_LOG_HEADER_START  (MEM_PACK_BL_END)
#define MEM_LOG_HEADER_END    (MEM_LOG_HEADER_START + MEM_LOG_HEADER_SIZE * MEM_LOG_NUM)
#define MEM_LOG_PARAM_START   (MEM_LOG_HEADER_END)
#define MEM_LOG_PARAM_END     (MEM_LOG_PARAM_START + MEM_LOG_PARAM_SIZE * MEM_LOG_NUM)


/****************************** Csms settings *********************************/
#define MEM_CSMS_DATA_SIZE    (16)
#define MEM_CSMS_NUM          (128)
#define MEM_CSMS_BL_START     (MEM_LOG_PARAM_END)
#define MEM_CSMS_BL_END       (MEM_CSMS_BL_START + MEM_CSMS_DATA_SIZE * MEM_CSMS_NUM)


/**************************** Memory for FW update ****************************/
#define MEM_FW_START_ADDR     (GSSWOP_START_ADDR + GSSWOP_MEM_SIZE)
#define MEM_FW_SIZE           (409600)                        // 400 kByte
#define MEM_FW_STAFF_ADDR     (MEM_FW_SIZE - 4096)


/******************************* Memory for Logs ******************************/
#define MEM_LOG_START_ADDR    (MEM_FW_START_ADDR + MEM_FW_SIZE)
#define MEM_LOG_END_ADDR      (FMEMORY_VOLUME - 1)
#define MEM_LOG_SIZE          (FMEMORY_VOLUME - MEM_LOG_START_ADDR)




#endif